#include <stdio.h>
#include <unistd.h>

#include "info.h"
#include"core_conf.h"
#include"node.h"
#include"client_connect.h"

extern struct client_connect *CC;
extern struct core_conf *Core_conf;

static void print_blanks(int n)
{
	int i = 0;
	for ( ; i < n; i++) {
		printf(" ");
	}
}

/*
void sklcc_dpi_platform_info(void)
{
	int cols = get_screen_cols();
	int space = cols / 2 - 15;
	space = space > 0 ? space : cols / 3;

	printf("\n");
	print_blanks(space);
	printf("=================================\n");
	print_blanks(space);
	printf("  Welcome to sklcc-dpi-platform\n");
	print_blanks(space);
	printf("=================================\n");
	printf("\n");
	sleep(2);
	int i = 0;
	for ( ; i < cols; i++) {
		printf("-");
	}
	printf("\n");
}
*/
/*
void print_config(void)
{
	printf("\nSystem will be launched with following configures:\n");
	printf("\n");
	printf("CORE_CONF_FILE: %s\n", core_conf.core_conf_file);
	printf("USE OLD_MODE: %s\n", core_conf.old_mode == 0 ? "NO" : "YES");
	if (core_conf.old_mode == 1) {
		printf("OLD_MODE_CORE_PATH: %s\n", core_conf.old_mode_core_path);
	} else {
		printf("PCAP_MODE: %s\n", core_conf.pcap_mode == 0 ? "OFFLINE" : "LIVE");

		if (core_conf.pcap_mode == 0) {
			printf("PCAP_FILE: %s\n", core_conf.pcap_file);
		} else {
			printf("PCAP_INTERFACE: %s\n", core_conf.pcap_interface);
		}

		printf("USLEEP_TIME: %d\n", core_conf.usleep_time);

		printf("USE MEMORY MANAGER: %s\n", core_conf.use_mm == 0 ? "NO" : "YES");

		if (core_conf.use_mm == 1) {
			printf("MEMORY LIMIT: %ld\n", core_conf.mm_limit);
		}

		printf("USE FREE MODE: %d\n", core_conf.mode);

		if (core_conf.mode == 1) {
			printf("MAX_ID: %ld\n", core_conf.max_id);
		}

		printf("USE MAIL: %s\n", core_conf.use_mail == 0 ? "NO" : "YES");

		if (core_conf.use_mail == 1) {
			printf("MAIL ADDRESS: %s\n", core_conf.to);
		}
		
		struct db_data *db_data;
		db_data = (core_conf.db_info)->db_list_head;	
		while (db_data != NULL) {
			printf("DATABASE INFO: TYPE: %s, NAME: %s, USER: %s, PASSWD: %s, ADDRESS: %s\n", db_data->db_type_name, db_data->db_name, db_data->db_user_name, db_data->db_passwd, db_data->db_address);
			db_data = db_data->next;
		}
	}

	printf("\nLet's Go");
	fflush(stdout);

	int j = 0;
	while (j < 3) {
		printf(".");
		fflush(stdout);
		sleep(1);
		j++;
	}
	printf("\n");

	int cols = get_screen_cols();
	int i = 0;
	for ( ; i < cols; i++) {
		printf("-");
	}
	printf("\n");
}
*/
void print_socket_info()
{
	int space=600;

	printf("\n");
        printf("=================================\n");
        printf(" socket info :\n");
        printf("\n");
        sleep(2);

	printf("balance server info:\n");
	print_blanks(20);
	printf("port :%d\n",ntohs(Core_conf->balance_addr->sin_port));
	print_blanks(20);
	printf("ip : %s\n",inet_ntoa(Core_conf->balance_addr->sin_addr));
	int i=0;	
	printf("client info :\n");
	for(i=0;i<CC->real_node_num;i++)
	{
		print_blanks(20);
		printf("node%d\n  ",i);
		print_blanks(20);
		printf("port :%d\n",ntohs(CC->head[i].Node->sin_port));
		print_blanks(20);
		printf("ip addr : %s\n",inet_ntoa(CC->head[i].Node->sin_addr));
	}

	printf("\n");
	printf("\n");
	printf("\n");

}
